package com.mmp.main.servlet.report;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mmp.common.servlet.BasicServlet;
import com.mmp.main.entity.HospitalDevice;
import com.mmp.main.util.Default;
import com.mmp.main.util.Enums;

public class ViewDevicesNotInContract extends BasicServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		// prepare the table data, then pass as parameter to be fetched as table
		// datasource

		String jpql = "select h from HospitalDevice h where h.status != " + Enums.DEVICE_STATUS.SCRAPPED.getStatus()
				+ " and h.withinContract = false order by h.deviceName";
		
		List<HospitalDevice> deviceList = dbm.queryJPQL(jpql, null, HospitalDevice.class);
		if (deviceList == null || deviceList.isEmpty()) {
			announceErorrMessage(request, response, "لا يوجد أجهزة خارج العقد");
		} else {
			HashMap params = new HashMap();
			params.put(Default.REPORT_TITLE_PARAM_NAME, Enums.REPORT_TITLE.DEVICES_NOT_IN_CONTRACT.getReportTitle());
			params.put("deviceList", deviceList);
			viewPDFReport("rt10.jasper", null, params, response);
		}
	}
}
